//
//  CircleTextView.swift
//  amap
//
//  Created by James Karl on 2020/5/13.
//

import Foundation
import UIKit

public class RRectTextView : UIView {
    let fillColor: UIColor
    
    let borderRadius: Double
    let borderWidth: Double
    let borderColor: UIColor
    
    let text: String
    let textColor: UIColor
    let textSize: Double
    
    public init(
        text: String,
        frame: CGRect,
        fillColor: UIColor = .purple,
        borderRadius: Double = 6.0,
        borderWidth: Double = 1.0,
        borderColor: UIColor = .red,
        textColor: UIColor = .white,
        textSize: Double = 20.0
    ) {
        self.text = text
        self.textSize = textSize
        self.textColor = textColor
        
        self.borderRadius = borderRadius
        self.borderWidth = borderWidth
        self.borderColor = borderColor
        
        self.fillColor = fillColor
        
        super.init(frame: frame)
        
        initViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func initViews() {
        self.backgroundColor = fillColor
        self.layer.cornerRadius = CGFloat(borderRadius)
        self.layer.borderWidth = CGFloat(borderWidth)
        self.layer.borderColor = borderColor.cgColor
        self.layer.shadowRadius = 0.0
        self.layer.masksToBounds = true
        
        let centerText = UILabel(frame: self.frame)
        centerText.textColor = textColor
        centerText.font = UIFont.systemFont(ofSize: CGFloat(textSize))
        centerText.text = text
        centerText.textAlignment = .center
        
        self.addSubview(centerText)
    }
    
}
